$(function() {
			initOrder();
		});

function initOrder() {
	$("#subBtn").click(function() {
		var cansubmit=false;
				var inputs = $("input[notnull='true']");
				for (var i = 0; i < inputs.length; i++) {
					var input = inputs[i];
					var v = $(input).val();
					var id = $(input).attr("id");
					$("#" + id + "Div").removeClass("error");
					$("#" + id + "Error").hide();
					if (v == "") {
						showError(id, "不能为空");
						$(input).focus();
						return false;
					}
				}
				cansubmit=checkuid();
				cansubmit=cansubmit&&checkImge();
				if(cansubmit&&confirm("确定要提交么？")){
					$("#orderForm").submit();
				}
			});
}

function showError(id, error) {
	$("#" + id + "Error").html(error).show();
	$("#" + id + "Div").addClass("error");
}

function checkImge() {
	var pic1 = $("#pic1").val();
	var pic2 = $("#pic2").val();
	pic1 = pic1.substring(pic1.lastIndexOf(".") + 1, pic1.length);
	pic2 = pic2.substring(pic2.lastIndexOf(".") + 1, pic2.length);
	var imgages = ["jpg", "jpeg", "png"];
	if ($.inArray(pic1, imgages) == -1) {
		showError("pic1", "请上传图片格式只能是" + imgages.join(","));
		$("#pic1").focus();
		return false;
	}
	if ($.inArray(pic2, imgages) == -1) {
		showError("pic2", "请上传图片格式只能是" + imgages.join(","));
		$("#pic2").focus();
		return false;
	}
	return true;
}

function checkuid() {
	var uid = $("#uid").val();
	if (uid.length != 15 && uid.length != 18) {
		showError("uid", "请上传正确的身份证号码");
		$("#uid").focus();
		return false;
	}
	return true;
}